<?php
$this->breadcrumbs = array(
	'申购单列表',
);
if (Yii::app()->user->checkAccess('materialRequisitionManage')) {
	$this->userActions = array(
		array(
			'label' => '新建申购单',
			'url' => array(
				'create'
			)
		),
		array(
			'label' => '管理申购单',
			'url' => array(
				'admin'
			)
		),
	);
}
Yii::app()->clientScript
	->registerScript('search-material-requisition',
		"
var reloadStatistic=function(){
        var loading='努力计算中...';
        var formData=$('#material-requisition-search-form').serialize();
        var materialModelId=$('#" . CHtml::activeId($searchModel, 'materialModelId')
			. "').val();
        if(!materialModelId || materialModelId==0){
        	$('#material-requisition-result-statistic-total-amount').html('未选择物品');
        	return;
        }
        $('#material-requisition-result-statistic-total-amount').html(loading);
        jQuery.post( '" . $this->createUrl('indexStatistic')
			. "', formData,function(data){
        $('#material-requisition-result-statistic-total-amount').html(data.totalAmount);
        }, 'json' )
};

$('#material-requisition-search-button').click(function(){
        $.fn.yiiListView.update('material-requisition-list', {
                data: $('#material-requisition-search-form').serialize()
        });
		reloadStatistic();
        return false;
});
reloadStatistic();
");
?>

<h1>材料申购单</h1>
<div class="form">
<?php $form = $this
	->beginWidget('CActiveForm',
		array(
			'id' => 'material-requisition-search-form',
			'action' => Yii::app()->createUrl($this->route),
			'method' => 'get',
		));
?>

	<?php echo $form->errorSummary($searchModel); ?>
<fieldset>
<legend>搜索条件</legend>

	<div class="span-8">
		<?php echo $form->labelEx($searchModel, 'projectId'); ?>
		<?php $this->widget('widgets.project.JProjectSelector',
				array(
					'model' => $searchModel,
					'attribute' => 'projectId',
				));
		?>
	</div>
	<div class="span-10">
		<?php echo $form->labelEx($searchModel, 'submitDateMin'); ?>
		<?php $this
			->widget('zii.widgets.jui.CJuiDatePicker',
				array(
					'model' => $searchModel,
					'attribute' => 'submitDateMin',
				));
		?> - 
		<?php $this
			->widget('zii.widgets.jui.CJuiDatePicker',
				array(
					'model' => $searchModel,
					'attribute' => 'submitDateMax',
				));
		?>
	</div>
	<div class="clear"></div>
	<div class="span-8">
		<?php echo $form->labelEx($searchModel, 'token'); ?>
		<?php echo $form->textField($searchModel, 'token', array(
				'size' => 20
			));
		?>
	</div>
	<div class="span-10"><?php echo $form->labelEx($searchModel, 'materialModelId'); ?>
		<?php
		$this
			->widget('widgets.material.JMaterialModelSelector',
				array(
					'model' => $searchModel,
					'attribute' => 'materialModelId',
				));
		?></div>
	<div class="clear"></div>

	<div class="row buttons">
		<?php echo CHtml::submitButton('搜索',
			array(
				'id' => 'material-requisition-search-button'
			));
		?>
	</div>

</fieldset>
<?php $this->endWidget(); ?>
</div>
<div id="material-requisition-result-statistic">
        <div id="material-requisition-statistic-title">统计</div>
        <div class="span-2">总量：</div>
        <div id="material-requisition-result-statistic-total-amount" class="span-3"></div>
        <div class="clear"></div>
</div>
<?php $this
	->widget('zii.widgets.CListView',
		array(
			'id' => 'material-requisition-list',
			'dataProvider' => $dataProvider,
			'itemView' => '_view',
			'separator' => '<div class="list-item-separator"></div>',
		));

?>
